//
//  NewPasswordViewController.swift
//  AnJiBei
//
//  Created by 赵鑫 on 15/10/31.
//  Copyright © 2015年 赵鑫. All rights reserved.
//

import UIKit

class NewPasswordViewController: BaseViewController {
    
    
    @IBOutlet weak var userFirstPassWordTextField: UITextField!
    
    @IBOutlet weak var userSecondPassWordTextField: UITextField!
    
    var userPhone:String?

    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        
       // print(userPhone)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /****************check操作****************/
    //密码检测
    func passWordSame() {
    
        if userFirstPassWordTextField.text!.isEmpty || userSecondPassWordTextField.text!.isEmpty {
        
            disPlayMessage("有输入为空，请输入完整")
        }
        
        else {
        
            if userFirstPassWordTextField.text!.characters.count < 6 || userSecondPassWordTextField.text!.characters.count < 6 {
            
                disPlayMessage("新密码小于6位，请至少输入6位密码")
            }
            else {
            
                if userFirstPassWordTextField.text! == userSecondPassWordTextField.text! {
                
                    requestNewpassWord()
                    
                }
                else {
                
                    disPlayMessage("密码输入不一致，请重新输入密码")
                }
            }
}
    }
    
    /***********button相关操作***********/
    
    @IBAction func checkNewPwButton(sender: UIButton) {
        passWordSame()
        
    }
    
    @IBAction func returnBack(sender: UIBarButtonItem) {
        
        self.dismissViewControllerAnimated(true, completion: nil)
    }
    
//    override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
//        
//    }
    
    /************model操作**************/
    func requestNewpassWord() {
    
        let userNewPassWord = UserNewPasswordModel()
        userNewPassWord.userPhone = userPhone!
        userNewPassWord.userPassword = userFirstPassWordTextField.text!
        
        startRequest(Constant.CHANGE_PASSWORD_URL, parm: userNewPassWord)
        
    }
    
    func requestDataNull(message: String) {
        //
       // disPlayMessage(message)
        
        self.performSegueWithIdentifier("NewPW2Login", sender: self)
    }
    
    func requestFailure(message: String) {
        //
        disPlayMessage(message)
    }
    func requestSuccess(json: AnyObject?, message: String) {
        //
    }
    
    func requestTimeOut(message: String) {
        //
        disPlayMessage(message)
    }
    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
